function showpic(obj) {
    var source = "/upload/images/" + obj;
    $("#image").attr("src", source);
    $("#image").css("display", "block")
}


var currentGid;

//RRR
function modify(obj) {
    $("#create").fadeOut();
    $("#warning").slideDown(500);
    $.post("student", {
        id: obj.value,
        option: "RRR"
    }, function (result) {
        console.log(result);
        if (result["err"] !== null) {
            alert("读取数据出现错误!")
        }
        currentGid = obj.value;
        $("#rname").val(result["obj"]["Name"]);
        $("#rident").val(result["obj"]["Ident"]);
        $("#rpassword").val(result["obj"]["Password"]);
        $("#rpoints").val(result["obj"]["Points"]);
        $("#rimage").val(result["obj"]["Image"]);

        var radio = $(".reffect");
        if (result["obj"]["Effect"] === 1) {
            radio[0].click()
        } else {
            radio[1].click()
        }
    })
}

//DDD UUU
$(function () {
    var modal = $("#warning");
    $("#miniclose").click(function () {
        modal.fadeOut()
    });
    $("#rdelete").click(function () {
        $.post("student", {
            id: currentGid,
            option: "DDD"
        }, function (result) {
            console.log(result);
            console.log(result["err"]);
            if (result["err"] === null) {
                alert("删除成功!");
                window.location.reload()
            } else {
                alert("删除失败!");
                modal.fadeOut(500);
            }
        })
    });
    $("#rcancle").click(function () {
        modal.fadeOut(500);
    });


    $("#rsure").click(function () {
        var radio = $(".reffect");
        var state;
        if (radio[0].checked === true) {
            state = 1
        } else {
            state = 0
        }
        var formData = new FormData($('#udreateinfo')[0]);
        formData.append("option", "UUU");
        formData.append("effect", state);
        formData.append("id", currentGid);
        $.ajax({
            type: "POST",
            url: "student",
            data: formData,
            processData: false,
            contentType: false,
            success: function (result) {
                console.log(result);
                if (result["err"] === null) {
                    alert("修改成功!");
                    window.location.reload()
                } else {
                    alert("修改失败!请确保身份证号正确!如有其它问题请联系开发商");
                    modal.fadeOut(500);
                }
            }
        })
    })
});

//CCC
$(function () {
    modal = $("#create");
    $("#createstudent").click(function () {
        $("#warning").fadeOut(500);
        modal.slideDown()
    });

    $("#ccancle").click(function () {
        modal.fadeOut(500);
    });
    $("#csure").click(function () {
        var radio = $(".ceffect");
        var state;
        if (radio[0].checked === true) {
            state = 1
        } else {
            state = 0
        }
        var formData = new FormData($('#createinfo')[0]);
        formData.append("option", "CCC");
        formData.append("effect", state);
        $.ajax({
            type: "POST",
            url: "student",
            data: formData,
            processData: false,
            contentType: false,
            success: function (result) {
                console.log(result);
                if (result["err"] === null && result["row"] === 1) {
                    alert("增加成功!");
                    window.location.reload()
                } else {
                    alert("增加失败,请确保没有填写重复的身份证号并且身份证号码长度为18位");
                    modal.fadeOut(500);
                }
            }
        })
    });
    $("#miniclose2").click(function () {
        modal.fadeOut()
    })
});
